<template>
  <!--设备日志管理模块-->
  <div class="app-container">
    <!--查询条件区-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="设备名称" prop="devName">
        <el-input
          v-model="queryParams.devName"
          placeholder="请输入设备名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--快捷按钮区-->
    <!--表格数据区-->
    <el-table v-loading="loading" :data="logList">
      <el-table-column label="设备名称" align="center" key="devName" prop="devName"/>
      <el-table-column label="日志时间" align="center" key="logDate" prop="logDate"/>
      <el-table-column
        label="日志信息"
        align="center"
        width="100"
        class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleXiangxi(scope.row)"
          >查看日志详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"/>

    <!-- 查看明细分为2个部分（1：报名、签到、评价信息  2：总结信息）对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body @close="cancel">
      <div class="line">设备名称：{{log.devName}}</div>
      <div class="line">日志时间：{{log.logDate}}</div>
      <div class="line">日志内容：</div>
      <pre class="json">{{logObj}}</pre>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
   </div>
</template>

<script>
import {listLog,getLog} from "@/api/business/log";
export default {
  name: "Log",
  dicts: ['ga_sktr_pe_status','ga_sktr_pep_status'], //日志状态
  data() {
    return {
      loading: true, //表格遮罩层(用于表格刷新必须的)
      showSearch: true, //表格上方的大查询条件参数（是否显示搜索条件）（如果表格上方有查询条件并且有类似51行处的显示隐藏按钮，这个必须）
      queryParams: {  //表格上方的大查询条件参数
        pageNum: 1,
        pageSize: 10,
        devName: undefined,
      },
      total: 0, //表格总条数（如果有分页，这个必须）
      logList: [], //日志表格数据

      //弹出层相关
      title: "", //第一层弹出层标题（添加修改的弹出框）
      open: false, //是否显示弹出层，第一层（这个必须）
      log:{}, //用于显示日志的详情

      logObj:{}, //用于保存转换后的json对象
      //在此之上补充页面属性
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //查询订单列表
    getList() {
      this.loading = true;
      listLog(this.queryParams).then(response => {
        console.log("获取日志列表接口返回值==",response.rows);
        this.logList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //表格上方，点击搜索按钮操作（表格搜索）
    handleQuery() {
      this.queryParams.pageNum=1;
      this.getList();
    },
    //表格上方，点击重置按钮操作
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //表格每行数据，点击"查看详细"按钮操作
    handleXiangxi(row) {
      var that=this;
      const devlogId = row.devlogId;
      this.title = "日志详细信息";
      this.open = true;
      getLog(devlogId).then(response => {
        console.log("根据id获取日志信息的返回值==",response.data);
        that.log=response.data;
        that.logObj=JSON.parse(that.log.log);
        var msgObj=JSON.parse(that.logObj.msg);
        that.logObj.msg=msgObj;
        console.log("转换后的log.log字段==",that.logObj);
        console.log("转换后的log.log.msg字段==",msgObj);
      });
    },
    //对话框全局操作
    //取消按钮
    cancel() {
      this.open = false;
      this.log={};
      this.logObj={};
    },

    //在此上方补充方法
  }
};
</script>
<style scoped lang="scss">
pre {
  white-space: pre-wrap;
  white-space: -moz-pre-wrap;
  white-space: -pre-wrap;
  white-space: -o-pre-wrap;
  word-wrap: break-word;
}
.json {
  background-color: #f0f0f0;
  padding: 10px;
  color: #333;
  font-family: monospace;
}
.line{
  width: 100%;
  height: 30px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 16px;
  font-family: MicrosoftYaHei;
  /*font-weight: bolder;*/
  text-align: left;
  line-height: 30px;
}
</style>

